home *** CD-ROM | disk | FTP | other *** search
Text File | 1995-11-08 | 19.6 KB | 659 lines | [TEXT/MPS ] |
- //========================================================================================
- //
- // File: FWPxyFrm.cpp
- // Release Version: $ 1.0d11 $
- //
- // Copyright: © 1995 by Apple Computer, Inc., all rights reserved.
- //
- //========================================================================================
-
- #include "FWFrameW.hpp"
-
- #ifndef FWPXYFRM_H
- #include "FWPxyFrm.h"
- #endif
-
- #ifndef FWPARTNG_H
- #include "FWPartng.h"
- #endif
-
- #ifndef FWFRMING_H
- #include "FWFrming.h"
- #endif
-
- #ifndef FWPROXY_H
- #include "FWProxy.h"
- #endif
-
- #ifndef FWUTIL_H
- #include "FWUtil.h"
- #endif
-
- #ifndef FWCLNINF_H
- #include "FWClnInf.h"
- #endif
-
- // ----- OS Layer -----
-
- #ifndef FWBARRAY_H
- #include "FWBArray.h"
- #endif
-
- #ifndef FWGRUTIL_H
- #include "FWGrUtil.h"
- #endif
-
- #ifndef FWODGEOM_H
- #include "FWODGeom.h"
- #endif
-
- // ----- OpenDoc Includes -----
-
- #ifndef SOM_ODFrame_xh
- #include <Frame.xh>
- #endif
-
- #ifndef SOM_ODFacet_xh
- #include <Facet.xh>
- #endif
-
- #ifndef SOM_Module_OpenDoc_StdProps_defined
- #include <StdProps.xh>
- #endif
-
- #ifndef SOM_ODStorageUnitView_xh
- #include <SUView.xh>
- #endif
-
- #ifndef SOM_Module_OpenDoc_StdTypes_defined
- #include <StdTypes.xh>
- #endif
-
- #ifndef SOM_ODEmbeddedFramesIterator_xh
- #include <EmbFrItr.xh>
- #endif
-
- #ifndef SOM_ODTransform_xh
- #include <Trnsform.xh>
- #endif
-
- #ifndef SOM_ODDraft_xh
- #include <Draft.xh>
- #endif
-
- //========================================================================================
- // RunTime Info
- //========================================================================================
-
- #if FW_LIB_EXPORT_PRAGMAS
- #pragma lib_export on
- #endif
-
- #ifdef FW_BUILD_MAC
- #pragma segment fw_embedding
- #endif
-
- //========================================================================================
- // class FW_CProxyFrame
- //========================================================================================
-
- //----------------------------------------------------------------------------------------
- // FW_CProxyFrame::FW_CProxyFrame
- //----------------------------------------------------------------------------------------
-
- FW_CProxyFrame::FW_CProxyFrame(Environment* ev,
- FW_CEmbeddingPart* part) :
- fPart(part),
- fProxy(NULL),
- fFrameID(kODNULLID),
- fContainingFrameID(kODNULLID),
- fEmbeddedFrame(NULL),
- fPurgeable(FALSE),
- fAttached(TRUE)
- {
- FW_ASSERT(fPart != NULL);
-
- // ----- Add it to the part -----
- fPart->PrivAddProxyFrame(ev, this);
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CProxyFrame::FW_CProxyFrame
- //----------------------------------------------------------------------------------------
-
- FW_CProxyFrame::FW_CProxyFrame(Environment* ev,
- FW_CEmbeddingPart* part,
- FW_MProxy* proxy,
- FW_CEmbeddingFrame* containingFrame,
- ODFrame* embeddedFrame) :
- fPart(part),
- fProxy(proxy),
- fFrameID(kODNULLID),
- fContainingFrameID(kODNULLID),
- fEmbeddedFrame(embeddedFrame),
- fPurgeable(FALSE),
- fAttached(TRUE)
- {
- FW_ASSERT(fPart != NULL);
- FW_ASSERT(fProxy != NULL);
- FW_ASSERT(containingFrame != NULL);
- FW_ASSERT(fEmbeddedFrame != NULL);
- FW_ASSERT(containingFrame->GetPart(ev) == part);
-
- fEmbeddedFrame->Acquire(ev);
- fFrameID = fEmbeddedFrame->GetID(ev);
-
- fContainingFrameID = containingFrame->GetID(ev);
-
- #ifdef FW_DEBUG
- {
- FW_CAcquiredODFrame aqContainingFrame = embeddedFrame->AcquireContainingFrame(ev);
- FW_ASSERT(aqContainingFrame == containingFrame->GetODFrame(ev));
- }
- #endif
-
- // ----- add it to the proxy -----
- fProxy->PrivAddProxyFrame(ev, this);
-
- FW_TRY {
- // ----- Add it to the part -----
- fPart->PrivAddProxyFrame(ev, this);
-
- FW_TRY {
- // ----- Add it to the embedding frame -----
- containingFrame->PrivAddProxyFrame(ev, this);
- }
- FW_CATCH_BEGIN
- FW_CATCH_EVERYTHING () {
- fPart->PrivRemoveProxyFrame (ev, this);
- FW_THROW_SAME ();
- }
- FW_CATCH_END
- }
- FW_CATCH_BEGIN
- FW_CATCH_EVERYTHING () {
- fProxy->PrivRemoveProxyFrame (ev, this);
- FW_THROW_SAME ();
- }
- FW_CATCH_END
-
- // ----- If the frame was in Limbo -----
- embeddedFrame->SetInLimbo(ev, FALSE);
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CProxyFrame::FW_CProxyFrame
- //----------------------------------------------------------------------------------------
-
- FW_CProxyFrame::FW_CProxyFrame(Environment* ev,
- FW_CEmbeddingPart* part,
- FW_MProxy* proxy,
- ODStorageUnitID embeddedFrameID) :
- fPart(part),
- fProxy(proxy),
- fFrameID(embeddedFrameID),
- fContainingFrameID(kODNULLID),
- fEmbeddedFrame(NULL),
- fPurgeable(FALSE),
- fAttached(TRUE)
- {
- FW_ASSERT(fPart != NULL);
- FW_ASSERT(fProxy != NULL);
- FW_ASSERT(embeddedFrameID != kODNULLID);
-
- // ----- add it to the proxy -----
- fProxy->PrivAddProxyFrame(ev, this);
-
- // ----- Add it to the part -----
- fPart->PrivAddProxyFrame(ev, this);
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CProxyFrame::~FW_CProxyFrame
- //----------------------------------------------------------------------------------------
-
- FW_CProxyFrame::~FW_CProxyFrame()
- {
- if (fEmbeddedFrame)
- {
- Environment* ev = somGetGlobalEnvironment();
- if (fEmbeddedFrame->IsInLimbo(ev))
- fEmbeddedFrame->Remove(ev);
- else
- fEmbeddedFrame->Release(ev);
- }
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CProxyFrame::GetContainingFrame
- //----------------------------------------------------------------------------------------
- // GetContainingFrame returns null if the containing frame of this proxyframe is not a valid
- // display frame
-
- FW_CEmbeddingFrame* FW_CProxyFrame::GetContainingFrame(Environment* ev) const
- {
- FW_CProxyFrame* self = (FW_CProxyFrame*)this;
-
- if (fPart->IsValidDisplayFrame(ev, fContainingFrameID))
- {
- FW_CAcquiredODFrame aqContainingODFrame = fPart->GetStorageUnit(ev)->GetDraft(ev)->AcquireFrame(ev, fContainingFrameID);
-
- FW_CEmbeddingFrame* containingFrame = FW_CEmbeddingFrame::ODtoFWEmbeddingFrame(ev, aqContainingODFrame);
- FW_ASSERT(containingFrame != NULL);
-
- return containingFrame;
- }
-
- return NULL;
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CProxyFrame::GetFrame
- //----------------------------------------------------------------------------------------
-
- ODFrame* FW_CProxyFrame::GetFrame(Environment* ev) const
- {
- if (fEmbeddedFrame == NULL)
- {
- FW_CProxyFrame* self = (FW_CProxyFrame*)this;
-
- self->fEmbeddedFrame = fPart->GetStorageUnit(ev)->GetDraft(ev)->AcquireFrame(ev, fFrameID);
- if (fAttached)
- fEmbeddedFrame->SetInLimbo(ev, FALSE); // Just in case
-
- FW_ASSERT(fEmbeddedFrame != NULL);
- }
-
- return fEmbeddedFrame;
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CProxyFrame::IsVisible
- //----------------------------------------------------------------------------------------
-
- FW_Boolean FW_CProxyFrame::IsVisible(Environment* ev, ODFacet* containingFacet, const FW_CRect& bounds) const
- {
- FW_CAcquiredODShape aqClipShape = containingFacet->AcquireClipShape(ev, NULL);
- FW_CRect clipRect = FW_GetShapeBoundingBox(ev, aqClipShape);
-
- FW_CAcquiredODTransform aqInternalTransform = containingFacet->GetFrame(ev)->AcquireInternalTransform(ev, NULL);
- FW_CRect tempRect = bounds.TransformCopy(ev, aqInternalTransform);
-
- if (clipRect.IsIntersecting(tempRect))
- return TRUE;
-
- return FALSE;
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CProxyFrame::SetPurgeable
- //----------------------------------------------------------------------------------------
-
- void FW_CProxyFrame::SetPurgeable(Environment* ev, FW_Boolean purgeable)
- {
- fPurgeable = purgeable;
-
- if (!fPurgeable)
- {
- FW_Boolean wasInMemory = IsFrameInMemory(ev);
-
- GetFrame(ev); // to be sure that the frame is in memory
-
- // ----- Create facets for the new frame if it was not in memory-----
- if (!wasInMemory)
- {
- FW_ASSERT(fPart->IsValidDisplayFrame(ev, fContainingFrameID));
- GetContainingFrame(ev)->PrivCreateEmbeddedFacets(ev, fProxy, this);
- }
- }
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CProxyFrame::Close
- //----------------------------------------------------------------------------------------
-
- void FW_CProxyFrame::Close(Environment* ev)
- {
- // if fEmbeddedFrame == NULL it is already closed
- if (fEmbeddedFrame == NULL)
- return;
-
- // ----- Close the frame -----
- fEmbeddedFrame->Close(ev); // Will call release
- fEmbeddedFrame = NULL;
- }
-
- //----------------------------------------------------------------------------------------
- // ExternalizeInScope
- //----------------------------------------------------------------------------------------
-
- static void ExternalizeInScope(Environment* ev, ODPart* thePart, ODFrame* scopeFrame)
- {
- ODEmbeddedFramesIterator* ite = thePart->CreateEmbeddedFramesIterator(ev, scopeFrame);
- for (ODFrame* embeddedFrame = ite->First(ev); ite->IsNotComplete(ev); embeddedFrame = ite->Next(ev))
- {
- FW_CAcquiredODFrame aqContainingFrame = embeddedFrame->AcquireContainingFrame(ev);
- if (aqContainingFrame == scopeFrame)
- {
- FW_CAcquiredODPart aqEmbeddedPart = embeddedFrame->AcquirePart(ev);
-
- embeddedFrame->Externalize(ev);
- aqEmbeddedPart->Externalize(ev);
-
- ExternalizeInScope(ev, aqEmbeddedPart, embeddedFrame);
- }
- }
-
- delete ite;
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CProxyFrame::Purge
- //----------------------------------------------------------------------------------------
-
- ODSize FW_CProxyFrame::Purge(Environment* ev)
- {
- if (!IsFrameInMemory(ev))
- return 0; // already gone
-
- // [HLX] I am not sure about that. If purge is called in a middle of a drag&drop I
- // may not be the owner of this frame anymore ????
- FW_CAcquiredODFrame aqODContainingFrame = fEmbeddedFrame->AcquireContainingFrame(ev);
- FW_CAcquiredODPart aqODContainingPart = aqODContainingFrame->AcquirePart(ev);
- if (aqODContainingPart != fPart->GetODPart(ev))
- fPurgeable = FALSE;
-
- if (fPurgeable)
- {
- // ----- HLX] OpenDoc Bug????
- fEmbeddedFrame->Externalize(ev);
- FW_CAcquiredODPart aqEmbeddedPart = fEmbeddedFrame->AcquirePart(ev);
- aqEmbeddedPart->Externalize(ev);
- ExternalizeInScope(ev, aqEmbeddedPart, fEmbeddedFrame);
- // ----- [HLX] OpenDoc Bug????
-
- // ----- Remove its facets
- FW_ASSERT(fPart->IsValidDisplayFrame(ev, fContainingFrameID));
- GetContainingFrame(ev)->PrivRemoveEmbeddedFacets(ev, this);
-
- // ----- Now I can close the frame
- Close(ev);
- }
-
- return 0; // [HLX] need to be able to get the size of what I am releasing
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CProxyFrame::InternalizeProxyFrame
- //----------------------------------------------------------------------------------------
- // returns true if valid
-
- FW_Boolean FW_CProxyFrame::InternalizeProxyFrame(Environment* ev, ODStorageUnitView* suView, FW_CCloneInfo* cloneInfo)
- {
- ODStorageUnitRef aSURef;
-
- FW_CByteArray byteArray;
- suView->GetValue(ev, sizeof(ODStorageUnitRef), byteArray);
- byteArray.CopyBuffer(&aSURef, sizeof(ODStorageUnitRef));
-
- if (!suView->IsValidStorageUnitRef(ev, aSURef))
- return FALSE;
-
- ODStorageUnitID fromFrameID = suView->GetIDFromStorageUnitRef(ev, aSURef);
-
- if (cloneInfo != NULL)
- {
- // ----- We are cloning -----
- fFrameID = cloneInfo->Clone(ev, fromFrameID, 0, 0);
- fContainingFrameID = cloneInfo->GetScopeFrame(ev)->GetID(ev);
- }
- else
- {
- // ----- We are just reading -----
- fFrameID = fromFrameID;
-
- // ----- Cache the id of the containing frame -----
- FW_CAcquiredODStorageUnit aqFrameSU = suView->GetStorageUnit(ev)->GetDraft(ev)->AcquireStorageUnit(ev, fFrameID);
- aqFrameSU->Focus(ev, kODPropContainingFrame, kODPosUndefined, kODWeakStorageUnitRef, 0, kODPosUndefined);
-
- aqFrameSU->GetValue(ev, sizeof(ODStorageUnitRef), byteArray);
- byteArray.CopyBuffer(&aSURef, sizeof(ODStorageUnitRef));
-
- if (aqFrameSU->IsValidStorageUnitRef(ev, aSURef))
- fContainingFrameID = aqFrameSU->GetIDFromStorageUnitRef(ev, aSURef);
- else
- fContainingFrameID = kODNULLID;
- }
-
- return TRUE;
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CProxyFrame::ExternalizeProxyFrame
- //----------------------------------------------------------------------------------------
-
- FW_Boolean FW_CProxyFrame::ExternalizeProxyFrame(Environment* ev, ODStorageUnitView* suView, FW_CCloneInfo* cloneInfo)
- {
- FW_ASSERT(fPart->IsValidDisplayFrame(ev, fContainingFrameID));
-
- FW_Boolean externalize = FALSE;
- ODStorageUnitID frameID = fFrameID;
-
- if (cloneInfo != NULL)
- {
- if (cloneInfo->GetScopeFrame(ev) == NULL)
- externalize = GetContainingFrame(ev)->IsPersistent(ev); // Only clone frames with a persistent containing Frame
- else
- externalize = (cloneInfo->GetScopeFrame(ev)->GetID(ev) == fContainingFrameID);
-
- if (externalize)
- frameID = cloneInfo->Clone(ev, fFrameID, 0, fFrameID);
- }
- else
- {
- // We only externalize frame that have a persistent containing Frame
- externalize = GetContainingFrame(ev)->IsPersistent(ev);
- }
-
- if (externalize)
- {
- ODStorageUnitRef aSURef;
-
- // ----- Write out the embedded frame reference -----
- FW_CByteArray byteArray(&aSURef, sizeof(ODStorageUnitRef));
- suView->GetStrongStorageUnitRef(ev, frameID, aSURef);
- suView->SetValue(ev, byteArray);
- }
-
- return externalize;
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CProxyFrame::SetProxy
- //----------------------------------------------------------------------------------------
-
- void FW_CProxyFrame::SetProxy(Environment* ev, FW_MProxy* proxy)
- {
- FW_ASSERT(fProxy == NULL || proxy == NULL || fProxy == proxy);
- fProxy = proxy;
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CProxyFrame::SetContainingFrame
- //----------------------------------------------------------------------------------------
- // We can't change the containing frame is this proxyframe is not orphaned
-
- void FW_CProxyFrame::SetContainingFrame(Environment* ev, FW_CEmbeddingFrame* containingFrame)
- {
- FW_ASSERT(IsOrphan(ev));
- fContainingFrameID = containingFrame->GetID(ev);
-
- ODFrame* embeddedFrame = GetFrame(ev); // Need to bring it into memory
- embeddedFrame->SetContainingFrame(ev, containingFrame->GetODFrame(ev));
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CProxyFrame::HasASelectedFacet
- //----------------------------------------------------------------------------------------
-
- FW_Boolean FW_CProxyFrame::HasASelectedFacet(Environment* ev) const
- {
- return fProxy->GetSelectState(ev);
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CProxyFrame::PrivAttach
- //----------------------------------------------------------------------------------------
-
- void FW_CProxyFrame::PrivAttach(Environment* ev)
- {
- FW_CEmbeddingFrame* embeddingFrame = GetContainingFrame(ev);
- if (embeddingFrame != NULL && !fAttached)
- {
- // [HLX] I have to load the frame. Is this a problem?
- ODFrame* odEmbeddedFrame = GetFrame(ev);
-
- // ----- Add it from the part -----
- fPart->PrivAddProxyFrame(ev, this);
-
- odEmbeddedFrame->SetContainingFrame(ev, embeddingFrame->GetODFrame(ev));
- odEmbeddedFrame->SetInLimbo(ev, FALSE);
-
- // ----- Add it to the embedding frame -----
- embeddingFrame->PrivAddProxyFrame(ev, this);
-
- // ----- It is now attached -----
- fAttached = TRUE;
-
- // ----- Create the facets -----
- embeddingFrame->PrivCreateEmbeddedFacets(ev, fProxy, this);
- }
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CProxyFrame::PrivDetach
- //----------------------------------------------------------------------------------------
-
- void FW_CProxyFrame::PrivDetach(Environment* ev)
- {
- FW_CEmbeddingFrame* embeddingFrame = GetContainingFrame(ev);
- if (embeddingFrame != NULL && fAttached)
- {
- embeddingFrame->PrivRemoveEmbeddedFacets(ev, this);
-
- // [HLX] I have to load the frame. Is this a problem?
- ODFrame* odEmbeddedFrame = GetFrame(ev);
-
- // ----- Remove it from the embedding frame -----
- embeddingFrame->PrivRemoveProxyFrame(ev, this);
-
- // ----- Set the containing frame to null -----
- FW_CAcquiredODFrame aqODContainingFrame = odEmbeddedFrame->AcquireContainingFrame(ev);
- if (aqODContainingFrame == embeddingFrame->GetODFrame(ev))
- {
- odEmbeddedFrame->SetInLimbo(ev, TRUE);
- odEmbeddedFrame->SetContainingFrame(ev, NULL);
- }
-
- // ----- Remove it from the part -----
- fPart->PrivRemoveProxyFrame(ev, this);
-
- // ----- It is now detached -----
- fAttached = FALSE;
- }
-
- FW_ASSERT(GetRefCount() == 1);
- }
-
- //----------------------------------------------------------------------------------------
- // PrivAcquireProxyFrame
- //----------------------------------------------------------------------------------------
- // Called from FW_CEmbeddingPart, FW_CEmbeddingFrame and FW_MProxy::PrivAcquireProxyFrame
-
- FW_CProxyFrame* FW_CProxyFrame::PrivAcquireProxyFrame(Environment* ev, FW_CPrivOrderedCollection* proxyFrames, ODStorageUnitID frameID)
- {
- FW_COrderedCollectionIterator ite(proxyFrames);
- for (FW_CProxyFrame* proxyFrame = (FW_CProxyFrame*)ite.First(); ite.IsNotComplete(); proxyFrame = (FW_CProxyFrame*)ite.Next())
- {
- if (frameID == proxyFrame->GetFrameID(ev))
- {
- proxyFrame->Acquire();
- return proxyFrame;
- }
- }
-
- return NULL;
- }
-
- //========================================================================================
- // class FW_CAcquiredProxyFrame
- //========================================================================================
-
- //----------------------------------------------------------------------------------------
- // FW_CAcquiredProxyFrame::FW_CAcquiredProxyFrame
- //----------------------------------------------------------------------------------------
-
- FW_CAcquiredProxyFrame::FW_CAcquiredProxyFrame() :
- fProxyFrame(NULL)
- {
- FW_END_CONSTRUCTOR
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CAcquiredProxyFrame::FW_CAcquiredProxyFrame
- //----------------------------------------------------------------------------------------
-
- FW_CAcquiredProxyFrame::FW_CAcquiredProxyFrame(FW_CProxyFrame* proxyFrame) :
- fProxyFrame(proxyFrame)
- {
- FW_END_CONSTRUCTOR
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CAcquiredProxyFrame::FW_CAcquiredProxyFrame
- //----------------------------------------------------------------------------------------
-
- FW_CAcquiredProxyFrame::FW_CAcquiredProxyFrame(const FW_CAcquiredProxyFrame& other) :
- fProxyFrame(other.fProxyFrame)
- {
- fProxyFrame->Acquire();
- FW_END_CONSTRUCTOR
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CAcquiredProxyFrame::~FW_CAcquiredProxyFrame
- //----------------------------------------------------------------------------------------
-
- FW_CAcquiredProxyFrame::~FW_CAcquiredProxyFrame()
- {
- FW_START_DESTRUCTOR
-
- if (fProxyFrame)
- fProxyFrame->Release();
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CAcquiredProxyFrame::operator=
- //----------------------------------------------------------------------------------------
-
- FW_CAcquiredProxyFrame& FW_CAcquiredProxyFrame::operator=(FW_CProxyFrame* proxyFrame)
- {
- if (fProxyFrame)
- fProxyFrame->Release();
- fProxyFrame = proxyFrame;
- return *this;
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CAcquiredProxyFrame::operator=
- //----------------------------------------------------------------------------------------
-
- FW_CAcquiredProxyFrame& FW_CAcquiredProxyFrame::operator=(const FW_CAcquiredProxyFrame& other)
- {
- if (fProxyFrame)
- fProxyFrame->Release();
- fProxyFrame = other.fProxyFrame;
- fProxyFrame->Acquire();
- return *this;
- }
-